package packageInputData;




import java.io.*;
import java.util.ArrayList;
import java.util.List;

import java.util.Calendar;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.sql.Timestamp;

import java.sql.Connection;
import java.sql.Date;
import java.sql.SQLException;


import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayListHandler;

/**
* @author LABIB TAKOUTI		 takouti.labib[AT]gmail.com
* @version 1.0 on 06/2012
*/


public class ReadInputData {
	
	private static String SlantFolderPath="";
	private static String RinexFolderPath="";
	private static String IgsFolderPath="";
	private static String ParamFilePath="";
	private static String AllGPSFilePath="";
	private static String GPSDataFilePath="";
	private static String AtmoStanFilePath="";
	private static String FrontFilePath="";
	private static String intreliefMatrix="";
	
	/**
	 * function to get the name of the file from its path
	* @param 			file		String, the file path 
	* @return			String		exact file name
	*/
	public static String getFileName(String file)
	{
		String name="";
		int i=file.lastIndexOf("/");
		int j=file.lastIndexOf("\\");
		if (i<j)
			i=j;
		for (int k=i+1; k<file.length();k++)
		{
			name=name+file.charAt(k);			
		}			
		return name;		
	}
	/**
	 * function to get the last id of the correspondent station id
	 * from table station_coord, else returns 0
	* @param 			sta_id		int, the id station 
	* @return			int		id of its last appearance in station_coord, 
	* 							0 if not existed
	*/
	@SuppressWarnings({ "deprecation", "rawtypes" })
	public static int getCoordId(int sta_id)
	{
		//connect to the database
		Connection conn=DbConnection.connectDB();					  			
	  	QueryRunner qRunner = new QueryRunner();
		List list1 = new ArrayList();
		//get a list of all id having the same sta_id value
				try {
				       list1 =(List) qRunner.query(conn,
									    		   "select id from station_coord where sta_id =?",
									    		   sta_id,
									    		   new ArrayListHandler());
				} catch (SQLException e2) {
				       e2.printStackTrace();
				}
		//get the last element		
		Object data[] = (Object[]) list1.get(list1.size()-1);
		//close connection
		DbUtils.closeQuietly(conn);
		//return the the id of the last element
		if(data.length!=0)
			return (int)Double.parseDouble(data[0].toString());
		else return 0;
	}
	/**
	 * function to get the string which starts after the end of the param string data_name 
	* @param 			strLine 	String, text line of the file,
	* 						 		a string name of variable to retrieve
	* @param 			data_name 	String, the file, the actual variable we need 
	* 								is just after "data_name" we inserted as entry
	* @return			String	 	the actual data we seek, in a string format
	*/
	public static String getData(String strLine, String data_name)
	{		
		String data="";
  		if (strLine.lastIndexOf(data_name)>0)
  		{
  			data=strLine.substring(data_name.length());			
  		}
  		return data;
	}
	/**
	 * function get a folder path and extract all files in it
	* @param 			repertoire File		 	directory path
	* @return			ArrayList <String> 		containing all files
	*/
	public static ArrayList<String> listeRepertoire ( File repertoire ) {
		ArrayList <String> file_list =new ArrayList<String>();
        
        if ( repertoire.isDirectory ( ) ) {
                File[] list = repertoire.listFiles();
                if (list != null){
	                for ( int i = 0; i < list.length; i++) {	                        
	                	if(!(list[i].toString().contains(".")))	                
	                		file_list.add(list[i].toString());
	                } 
                } else {
                	System.err.println(repertoire + " : Erreur de lecture.");
                }
        } 
        return file_list;
} 
	/**
	 * function make Timestamp time format from time data
	* @param 			year 		int, the year
	* @param 			doy 		int, the day of the year, (julian day)
	* @param 			hour 		String, the hour
	* @param 			min 		String, the miniute
	* @param 			sec 		String, the seconde
	* @return			timestamp	Timestamp, the actual data we seek, in a string format
	*/
	public static Timestamp convertToTimestamp (int year, int doy, String hour, String min, String sec)
	{
		Timestamp timestamp=null;
		if (year>3000 ||year <1000 ||doy<1 || doy >366)
		{System.out.println("wrong range of year or day of the year, cannot convert to timestamp\n");
		 System.exit(0);}
		else
		{
			//prepare timestamp format from data read from file
		    Calendar calendar = Calendar.getInstance();
		    calendar.set(Calendar.YEAR,year);
		    calendar.set(Calendar.DAY_OF_YEAR,doy);
		    
		    String yyyy,mm,dd, hh, mn,ss;
	  	
			yyyy=new Integer(year).toString();;
			mm=new Integer((calendar.get(2))+1).toString();
			dd=new Integer(calendar.get(5)).toString();
			hh=hour;
			mn=min;
			ss=sec;
			
						if (mm.length()<2) mm="0"+mm;
						if (dd.length()<2) dd="0"+dd;
						if (hh.length()<2) hh="0"+hh;
						if (mn.length()<2) mn="0"+mn;
						if (ss.length()<2) ss="0"+ss;
	
						timestamp = Timestamp.valueOf(
								yyyy+"-"+
								mm+"-"+
								dd+" "+
								hh+":"+
								mn+":"+
								ss);
		}
		return timestamp;
		
}
	/**
	 * function make timestamp time format from time data
	* @param 			year 		int, the year
	* @param 			doy 		int, the day of the year, (julian day)
	* @param 			hour 		String, the hour
	* @return			timestamp	Timestamp, the actual data we seek, in a string format
	*/
	public static Timestamp convertToTimestamp (int year, int doy, String hour)
{
	Timestamp timestamp=null;
	if (year>3000 ||year <1000 ||doy<1 || doy >366)
	{System.out.println("wrong range of year or day of the year, cannot convert to timestamp\n");
	 System.exit(0);}
	else
	{
		//prepare timestamp format from data read from file
	    Calendar calendar = Calendar.getInstance();
	    calendar.set(Calendar.YEAR,year);
	    calendar.set(Calendar.DAY_OF_YEAR,doy);
	    
	    String yyyy,mm,dd, hh, mn,ss;
  	
		yyyy=new Integer(year).toString();;
		mm=new Integer((calendar.get(2))+1).toString();
		dd=new Integer(calendar.get(5)).toString();
		hh=hour;
		mn="00";
		ss="0.00";
		
					if (mm.length()<2) mm="0"+mm;
					if (dd.length()<2) dd="0"+dd;
					if (hh.length()<2) hh="0"+hh;
					if (mn.length()<2) mn="0"+mn;
					if (ss.length()<2) ss="0"+ss;

					timestamp = Timestamp.valueOf(
							yyyy+"-"+
							mm+"-"+
							dd+" "+
							hh+":"+
							mn+":"+
							ss);
	}
	return timestamp;
	
} 
	/**
	 * function make timestamp time format from time data
	* @param 			year 		int, the year
	* @param 			doy 		int, the day of the year, (julian day)
	* @return			timestamp	Timestamp, the actual data we seek, in a string format
	*/
	public static Timestamp convertToTimestamp (int year, int doy)
{
	Timestamp timestamp=null;
	if (year>3000 ||year <1000 ||doy<1 || doy >366)
	{
	System.out.println("wrong range of year or day of the year, cannot convert to timestamp\n");
	System.exit(0);
	return null;
	 }
	else
	{
		//prepare timestamp format from data read from file
	    Calendar calendar = Calendar.getInstance();
	    calendar.set(Calendar.YEAR,year);
	    calendar.set(Calendar.DAY_OF_YEAR,doy);
	    
	    String yyyy,mm,dd, hh, mn,ss;
  	
		yyyy=new Integer(year).toString();;
		mm=new Integer((calendar.get(2))+1).toString();
		dd=new Integer(calendar.get(5)).toString();
		hh="00";
		mn="00";
		ss="0.00";
		
					if (mm.length()<2) mm="0"+mm;
					if (dd.length()<2) dd="0"+dd;
					if (hh.length()<2) hh="0"+hh;
					if (mn.length()<2) mn="0"+mn;
					if (ss.length()<2) ss="0"+ss;

					timestamp = Timestamp.valueOf(
							yyyy+"-"+
							mm+"-"+
							dd+" "+
							hh+":"+
							mn+":"+
							ss);
	}
	return timestamp;
	
}
	/**
	 * function to read igs data from file and insert them in database
	* @param 			file		String, file name, the total path
	*/
	@SuppressWarnings("rawtypes")
	public static void readIgsFile(String file)
	{
		
			//an arraylist to contain the igs datafilename_data
		  	ArrayList <String> igs_data =new ArrayList<String>();
		  	//an arraylist to contain the igs times
		  	ArrayList <String> igs_times =new ArrayList<String>();
		  	//String to contain the name of the file		  
		  	String file_name="";
		  	//String to contain file description		 
		  	String description="";
		  	//String to get the data line each time
		  	String [] data_line;
		  	//to get the result of the query
		  	int inserts=0;
		  	//to get the number of line
		  	int line_number=0;
		  	//to keep the actual id of both table igs & igs_time
		  	int igs_id=0, igs_time_id=0;
		  	//fileds into igs table
		  	int diw=0,week=0;
		  	
		
		try{
		  	// Open the file that is the first 
		  	// command line parameter
		  	FileInputStream fstream = new FileInputStream(file);
		  	// Get the object of DataInputStream
		  	DataInputStream in = new DataInputStream(fstream);
		  	BufferedReader br = new BufferedReader(new InputStreamReader(in));	  
		  	String strLine="";
		  	//get the actual file name, and its values
		  	file_name=getFileName(file);
		  	week=(int)Double.parseDouble(file_name.substring(3,7));
		  	diw=(int)Double.parseDouble(file_name.substring(7,8));
		  
		  	//System.out.println(file_name+"\n"+week+"\n"+diw);
		  	
		  	while ((strLine=br.readLine()) != null)   			  	
		  	{
		  		
		  		if (line_number<22)
		  		{
		  			description=description+strLine.toString()+"\n";
		  			line_number++;  			
		  		}
		  		else
				  		{if (!(description==""))
							  		{
					  			//insert into database into igs table
					  			Connection conn=DbConnection.connectDB();					  			
							  	QueryRunner qRunner = new QueryRunner();
					  			//prepare SQL query to insert into Table slant_delay
					  			String req="";
					  			req="INSERT INTO igs" +
									"(name, description, week,diw )" +				
									"VALUES (?,?,?,?)";
					  			
					  			inserts = qRunner.update(conn,req,
										file_name,description,week,diw);
					  			description="";
					  			
					  			igs_id=(Integer)DbConnection.getFromDB("id", "igs");
					  		
					  			
					  			//close the connection
					  			DbUtils.closeQuietly(conn);
							  		}
				  	
		  			//continue reading igs file
				  			if (strLine.contains("*")||strLine.contains("EOF"))
				  			{
				  				if (!(igs_times.isEmpty()))
				  				{
				  				//insert into database into igs table
						  			Connection conn=DbConnection.connectDB();
								  	QueryRunner qRunner = new QueryRunner();
								  	//prepare timestamp format from data read from file
								  	String yyyy,mm,dd, hh, mn,ss;
								  	
								  			yyyy=igs_times.get(1);
								  			mm=igs_times.get(2);
								  			dd=igs_times.get(3);
								  			hh=igs_times.get(4);
								  			mn=igs_times.get(5);
								  			ss=igs_times.get(6);
								  			
								  			if (mm.length()<2) mm="0"+mm;
								  			if (dd.length()<2) dd="0"+dd;
								  			if (hh.length()<2) hh="0"+hh;
								  			if (mn.length()<2) mn="0"+mn;
								  			if (ss.length()<2) ss="0"+ss;
								  	
								  	Timestamp timestamp = Timestamp.valueOf(
								  			yyyy+"-"+
								  			mm+"-"+
								  			dd+" "+
								  			hh+":"+
								  			mn+":"+
								  			ss);
								  	
						  			//prepare SQL query to insert into Table slant_delay
						  			String req="";
						  			req="INSERT INTO igs_times" +
										"(id_igs, tmstamp )" +				
										"VALUES (?,?)";
						  			inserts = qRunner.update(conn,req,igs_id,timestamp);
						  			
						  			
						  		//get the actual id of igs_time table
						  			List  list1 = new ArrayList();
						  			list1 =(List) qRunner.query(
						  					conn,
						  					"select * from igs_times_id_seq",
						  					new ArrayListHandler()
						  					);					  			
						  			//get the result
						  			Object data[] = (Object[]) list1.get(0);		  			
						  			String replace=data[1].toString();	
						  			//convert it to int
						  			igs_time_id=(int)Double.parseDouble(replace);
						  			
						  			int i=0;
						  			//insert into igs_data table
						  			req="INSERT INTO igs_data" +
									"(id_igs, id_igs_times, code_sat," +
									"sat,xsat,ysat,zsat,wsat)" +				
									"VALUES (?,?,?,?,?,?,?,?)";
						  			while(i<igs_data.size()){
					  			inserts = qRunner.update(conn,req,
										igs_id,
										igs_time_id,
										igs_data.get(i),
										(int)Double.parseDouble(igs_data.get(i).substring(2,4)),
										Double.parseDouble(igs_data.get(i+1)),
										Double.parseDouble(igs_data.get(i+2)),
										Double.parseDouble(igs_data.get(i+3)),
										Double.parseDouble(igs_data.get(i+4)));
						  				i=i+5;
						  			}
				  					igs_data.clear();
				  					igs_times.clear();
				  					
				  					//close the connection
				  		  			DbUtils.closeQuietly(conn);
				  				}
				  							  				
				  				data_line=strLine.split(" ");							  
					  			for (int i=0; i<data_line.length;i++)									
					  				if (!(data_line[i].isEmpty()))										
					  					igs_times.add(data_line[i]);		  				
				  			}
				  			else
				  			{
				  				data_line=strLine.split(" ");	
				  				int nb_element=0;
					  			for (int i=0; i<data_line.length;i++)									
					  				if ((!(data_line[i].isEmpty()))&&(nb_element<5))										
					  				{
					  					igs_data.add(data_line[i]);	
					  					nb_element++;
					  					}	
				  			}
				  			
				  		}
		  	
		  	//end of while (reading file line by line)
		  	}	
		  	if (inserts==1)
  				System.out.println("Insertion into igs data done !");
		  	
		 }
		catch (Exception e){
			//Catch exception if any
		 	 System.err.println("Error: " + e.getMessage());
			 }
		
		
		
	}
	/**
	 * function to read rinex data from file and insert them in database
	* @param 			file		String, file name, the total path
	*/
	public static void readRinexFile(String file)
	{
		
		//an arraylist to contain the rinex data
		  ArrayList <String> rinex_data =new ArrayList<String>();
		  //String to contain the name of the file		  
		  String file_name="";
		  //String to contain file description		 
		  String file_desc="";
		  //String to get the data line each time
		  String [] data_line;
		  //to get the result of the query
		  int inserts=0;
		  
			try{
			  	// Open the file that is the first 
			  	// command line parameter
			  	FileInputStream fstream = new FileInputStream(file);
			  	// Get the object of DataInputStream
			  	DataInputStream in = new DataInputStream(fstream);
			  	BufferedReader br = new BufferedReader(new InputStreamReader(in));	  
			  	String strLine;
			  	//get the actual file name
			  	file_name=getFileName(file);
			  	//extract data from file and putting them in ArratyList rinex_data 
			  	while ((strLine = br.readLine()) != null)   			  	
			  	{
			  		if (strLine.contains("Estimated atmospheric"))
			  		{
			  			file_desc=strLine.toString();
			  		}
			  		else if (!(strLine.contains("Yr")))
			  		{
			  			data_line=strLine.split(" ");							  
			  			for (int i=0; i<data_line.length;i++)									
			  				if (!data_line[i].isEmpty())										
			  					rinex_data.add(data_line[i]);
			  		}		  		
			  	}		  			
			 }
			catch (Exception e){
				//Catch exception if any
			 	 System.err.println("Error: " + e.getMessage());
				 }
	
		  //insert rinex values into the database
			Connection conn=DbConnection.connectDB();
			try {
	  			//prepare query runner
	  			QueryRunner qRunner = new QueryRunner();
	  			//prepare SQL query to insert into Table slant_delay
	  			String req="";
	  			req="INSERT INTO rinex" +
				"(name, description," +
				"doy," +
				"total_zen, wet_zen, " +
				"sig_zen, pw, " +
				"sig_pw, press," +
				"temp, zhd, qf_ztd, " +
				"grad_ew, sig_ew, " +
				"grad_ns, sig_ns, tmstamp,sat) " +
				"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
	  			
	  			Timestamp timestamp=null;
	  			//to get the sat code from the name of the file
	  			String [] name_decrypt;
	  			String [] name_decrypt1;
	  			name_decrypt=file_name.split("_");
	  			String sat=name_decrypt[2];
	  			name_decrypt1=sat.split("\\.");
	  			String sat1=name_decrypt1[0];
	  			
	  			for (int i=0;i<rinex_data.size();i+=18)
				{
	  			//prepare timestamp format from data read from file
		  		   
	  					timestamp=convertToTimestamp(
	  							(int)Double.parseDouble(rinex_data.get(i)),
	  							(int)Double.parseDouble(rinex_data.get(i+1)),
			  					rinex_data.get(i+2),
			  					rinex_data.get(i+3),
			  					new Double (Double.parseDouble(rinex_data.get(i+4))).toString());
	  				
	  						if((i%1000)==0)
	  								System.out.println((i/18)+" row inserted into rinex table");
		  	
		  	
	  				inserts = qRunner.update(conn,req,
	  						file_name,
	  						file_desc,
	  						(int)Double.parseDouble(rinex_data.get(i+1)),
	  						Double.parseDouble(rinex_data.get(i+5)),
	  						Double.parseDouble(rinex_data.get(i+6)),
	  						Double.parseDouble(rinex_data.get(i+7)),
	  						Double.parseDouble(rinex_data.get(i+8)),
	  						Double.parseDouble(rinex_data.get(i+9)),
	  						Double.parseDouble(rinex_data.get(i+10)),
	  						Double.parseDouble(rinex_data.get(i+11)),
	  						Double.parseDouble(rinex_data.get(i+12)),
	  						Double.parseDouble(rinex_data.get(i+13)),
	  						Double.parseDouble(rinex_data.get(i+14)),
	  						Double.parseDouble(rinex_data.get(i+15)),
	  						Double.parseDouble(rinex_data.get(i+16)),
	  						Double.parseDouble(rinex_data.get(i+17)),
	  						timestamp,
	  						sat1);
					
				}
	  			//test if good
	  			if (inserts==1)
	  				System.out.println("Insertion into rinex done !");
	  			//close the connection
  			DbUtils.closeQuietly(conn);
  			
		} catch (Exception e) {
		e.printStackTrace();
		}	
	}
	/**
	 * function to read the slant file and inserts values into the database
	* @param 			file		String, file name, the total path
	*/
	public static void readSlantFile(String file){
		 @SuppressWarnings("unused")
		String  st="";
		  //the actual name of the file
		  String file_name="";
		  file_name=getFileName(file);
		  //variable to contain the description of the abbreviation b
		  String description="";
		  //level is an indicator to show where i am in the file, in what section
		  int level=0;
		  //data_level_1 is an indicator to shows where i am in the data in level 1
		  int data_level_1=0;
		  //boolean to indicate the beginning of data
		  boolean bool=true;
		  //variable to contain slant delay data level 1
		  String  
		  number_of_stations="",
		  sampling_rate="",
		  number_of_satellites="",
		  number_of_slants="",
		  reference_MJD="",
		  begin_MJD="",
		  end_MJD="",
		  GPS_week="",
		  day_of_GPS_week="",
		  sort_key1="",
		  sort_key2="";
		  
		  //an ArrayList to contain the coordinates
		  ArrayList <String> coord =new ArrayList<String>();
		  //to contain every time a line of coordinates data
		  String []coord_line;
		  //the get the id of the actual slay_delay row, from the database
		  int current_value=1;
		  //an ArrayList to contain the satellite used
		  ArrayList <String> satelites =new ArrayList<String>();
		  //an ArrayList for the slant data
		  ArrayList <String> slant_data =new ArrayList<String>();
		  //to contain every time a line of coordinates data
		  String []data_line;
		  
		  
		  
		  
	try{
	  	// Open the file that is the first 
	  	// command line parameter
	  	FileInputStream fstream = new FileInputStream(file);
	  	// Get the object of DataInputStream
	  	DataInputStream in = new DataInputStream(fstream);
	  	BufferedReader br = new BufferedReader(new InputStreamReader(in));	  
	  	String strLine;
		//variable to contain each time a data name for the slant_delay
	  	String data_name="";
	  	//variable to determine if we reach the variable GPS_week
	  	//special treatment to eliminate problem with  variable day_of_GPS_week
	  	boolean gps_week_not_reached=true;
	  	//Read File Line By Line
	  	while ((strLine = br.readLine()) != null)   
	  	{
	  		
				  switch (level)
				  {
						  //section of the file where to define the file version
						  case 0:
							  if (strLine.contains("+slant_delay_param")){
								  level=1;
								  break;
							  }
							  break;	
						  //section of the file where to find data for slant_delay			 
						  case 1:
							  
							  
							  
							  if (strLine.contains("+sta_number_name_coordinate")||strLine.contains("-slant_delay_param")){				  ;
								  level=2;
								  break;
							  }
							  if (!strLine.contains("number_of_stations")&& bool)
							  {
								  description=description+strLine.toString()+"\n";				 
							  }
							  	else 
							  	{
							  		bool=false;
							  		switch (data_level_1)
							  		{										  		
										  		case 0:			  		
										  		data_name="number_of_stations ";
										  		number_of_stations=getData(strLine,data_name);
										  		data_level_1=1;
										  		break;
										  		
										  		case 1:
										  		data_name="sampling_rate ";
										  		sampling_rate=getData(strLine,data_name);
										  		data_level_1=2;
										  		break;
										  		
										  		case 2:
										  		data_name="number_of_satellites ";
										  		number_of_satellites=getData(strLine,data_name);
										  		data_level_1=3;
										  		break;
										  		
										  		case 3:
										  		data_name="number_of_slants ";
										  		number_of_slants=getData(strLine,data_name);
										  		data_level_1=4;
										  		break;
										  		
										  		case 4:
										  		data_name="reference_MJD ";
										  		reference_MJD=getData(strLine,data_name);
										  		data_level_1=5;
										  		break;
										  		
										  		case 5:
										  		data_name="begin_MJD ";
										  		begin_MJD=getData(strLine,data_name);
										  		data_level_1=6;
										  		break;
										  		
										  		case 6:
										  		data_name="end_MJD ";
										  		end_MJD=getData(strLine,data_name);
										  		data_level_1=7;
										  		break;
										  	
										  		case 7:
										  		//to prevent finding GPS_week in the next data searched "day_of_GPS_week"
										  		if (gps_week_not_reached){
										  		data_name="GPS_week ";
										  		GPS_week=getData(strLine,data_name);
										  		if (strLine.lastIndexOf("GPS_week")>0)
										  			gps_week_not_reached=false;
									  			}		
										  		data_level_1=8;
										  		break;
										  		
										  		case 8:
										  		data_name="day_of_GPS_week ";
										  		day_of_GPS_week=getData(strLine,data_name);
										  		data_level_1=9;
										  		break;
										  		
										  		case 9:
										  		data_name="sort_key1 ";
										  		sort_key1=getData(strLine,data_name);
										  		data_level_1=10;
										  		break;
										  		
										  		case 10:
										  		data_name="sort_key2 ";
										  		sort_key2=getData(strLine,data_name);
										  		data_level_1=11;
										  		break;
										  		default:
							  		}
							  	}
							  							  
							  break;
						  case 2:
							  //test we are always at level 2 in the file
							  if (strLine.contains("+satellites_used")||strLine.contains("-sta_number_name_coordinate")){
								  level=3;
								  break;
							  }
							  //take each data (5 data) and insert them in  arraylist coord
							  coord_line=strLine.split(" ");
							  for (int i=0; i<coord_line.length;i++)
									if (!coord_line[i].isEmpty())
										coord.add(coord_line[i]);
							  
							  
							  
							  break;
						  case 3:
							  if (strLine.contains("-satellites_used")){
								  level=4;
								  break;
							  }
							  satelites.add(strLine.toString().replace(" ", ""));
							  
							  break;
						  case 4:
							  if (strLine.contains("TIME      STA   SAT   ELEV   AZIMU   SLANT_TD SLANT_TDZ")||strLine.contains("---------------------------------------------------------"))
							  {								  
								  break;
							  }
							  if(strLine!= null){
							  data_line=strLine.split(" ");
							  for (int i=0; i<data_line.length;i++)
									if (!data_line[i].isEmpty()){
										slant_data.add(data_line[i]);
										
									}
							  }
							  
							  break;
						  default:
								  System.out.println ("No data in the file");
				  }	
	  } 
	  
	  //Close the input stream
	  in.close();
	
	}
		 catch (Exception e){
		//Catch exception if any
	 	 System.err.println("Error: " + e.getMessage());
		 }
	 
	
	
		String [] filename_data;
		filename_data=file_name.split("_");
		Timestamp tmstamp = convertToTimestamp(
				(int)Double.parseDouble(filename_data[2]),
				(int)Double.parseDouble(filename_data[3]),
				filename_data[4]); 
		
		
				Connection conn=DbConnection.connectDB();
		  		try {
		  			//prepare query runner
		  			QueryRunner qRunner = new QueryRunner();		  			
		  			//prepare SQL query to insert into Table slant_delay
		  			String req="";
		  			req="INSERT INTO slant_delay" +
					"(name, var_description, nb_station," +
					"sampling_rate, nb_satelite, nb_slant," +
					"ref_mjd, begin_mjd, end_mjd, " +
					"gps_week, day_gps_week, " +
					"sort_key1, sort_key2,doy,tmstamp) " +
					"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		  			
		  			//execute SQL query with  data
		  			int inserts = qRunner.update(conn,req,
		  					file_name,
							description,
							(int)Double.parseDouble(number_of_stations),
							(int)Double.parseDouble(sampling_rate),
							(int)Double.parseDouble(number_of_satellites),
							(int)Double.parseDouble(number_of_slants),
							Double.parseDouble(reference_MJD),
							Double.parseDouble(begin_MJD),
							Double.parseDouble(end_MJD),
							(int)Double.parseDouble(GPS_week),
							(int)Double.parseDouble(day_of_GPS_week),
							sort_key1,
							sort_key2,
							(int)Double.parseDouble(filename_data[3]),
							tmstamp);
		  			
		  			//test if good		  			
		  			if (inserts==1)
		  				System.out.println("Insertion into Slant_delay done ! ");
		  			
		  			//code to get the actual id, of slant_delay, from slant_delay_id_seq
		  			//in the database, and place it in "current_value"		  			
		  			
		  			current_value=(Integer)DbConnection.getFromDB("id", "slant_delay","name",file_name);
		  			
		  			
		  		//prepare SQL query to insert into Table coordinates
		  			req="INSERT INTO station_coord" +
					"(slant_id, sta_id, code," +
					"coord1, coord2, coord3)" +
					"VALUES (?,?,?,?,?,?)";
		  			
		  			for (int i=0; i<coord.size();i+=5)
			  		{
		  				inserts = qRunner.update(conn,req,
		  						current_value,
		  						(int)Double.parseDouble(coord.get(i)),
				  				coord.get(i+1),
				  				Double.parseDouble(coord.get(i+2)),
				  				Double.parseDouble(coord.get(i+3)),
				  				Double.parseDouble(coord.get(i+4)));
			  		}
		  			
		  			//test if good
		  			if (inserts==1)
		  				System.out.println("Insertion into station_coord done !");
		 		
		  		//prepare SQL query to insert into Table satellites
		  			req="INSERT INTO satelite_used" +
					"(slant_id, satelite)" +
					"VALUES (?,?)";
		  			//we start by 1, because satelites.get(0) contains
		  			//the string +"satellites_used"
		  			for (int i=1; i<satelites.size();i++)
			  		{
		  				inserts = qRunner.update(conn,req,
		  						current_value,
		  						(int)Double.parseDouble(satelites.get(i)));
			  		}
		  			
		  		//test if good
		  			if (inserts==1)
		  				System.out.println("Insertion into satelite_used done !");
		  			
		  			
		  		//prepare SQL query to insert into Table slant data
		  			req="INSERT INTO slant_data" +
					"(slant_id,station_coord_id, time, sta," +
					"sat, elev, azimu," +
					"slant_td, slant_tdz)" +
					"VALUES (?,?,?,?,?,?,?,?,?)";
		  			
		  			for (int i=0; i<slant_data.size();i+=7)
			  		{
		  				if((i%10000)==0)
		  					System.out.println((i/7)+"rows inserted into slant_data");
		  				//get the id of the specific station_coord
		  				int sta_id=(int)Double.parseDouble(slant_data.get(i+1))/100;
		  				
		  				//System.out.print("row: "+i);
		  				inserts = qRunner.update(conn,req,
		  						current_value,
		  						getCoordId(sta_id),
		  						Double.parseDouble(slant_data.get(i)),
		  						(int)Double.parseDouble(slant_data.get(i+1)),
		  						(int)Double.parseDouble(slant_data.get(i+2)),
				  				Double.parseDouble(slant_data.get(i+3)),
				  				Double.parseDouble(slant_data.get(i+4)),
				  				Double.parseDouble(slant_data.get(i+5)),
				  				Double.parseDouble(slant_data.get(i+6)));
			  		}
		  			//System.out.print(slant_data.size());
		  		//test if good
		  			if (inserts==1)
		  				System.out.println("Insertion into slant_data done for file: "+file);
		  			//close the connection
		  			DbUtils.closeQuietly(conn);
		  		} catch (Exception e) {
					e.printStackTrace();
				}
		  		coord.clear();
				satelites.clear();
				slant_data.clear();  		
	}
	/**
	 * function read all parameters from param.exp file 
	* @param 			file		String, file name, the total path
	*/
	public static void readParamFile(String file){
		
		//get all params from the file and put them in param_data
		ArrayList <String> param_data =new ArrayList<String>();		
		int inserts =0;
		try{
		  	// Open the file that is the first 
		  	// command line parameter
		  	FileInputStream fstream = new FileInputStream(file);
		  	// Get the object of DataInputStream
		  	DataInputStream in = new DataInputStream(fstream);
		  	BufferedReader br = new BufferedReader(new InputStreamReader(in));	  
		  	String [] data;
		  	String strLine;
		 	while ((strLine = br.readLine()) != null)   			  	
		  	{
		 		data=strLine.split("\t");
		 		param_data.add(data[data.length-1]);
		  	}
		 }
		catch (Exception e){
			//Catch exception if any
		 	 System.err.println("Error: " + e.getMessage());
			 }
		
						//get the session timestamp
						long time = System.currentTimeMillis();
				        Timestamp session=new Timestamp(time);
				        
				        //build the Date format from data
				        Date d=null;
				        d=Date.valueOf(	    		
					    		param_data.get(2).substring(0, 4) +	"-" +
					    		param_data.get(2).substring(4, 6)+	"-" +
					    		param_data.get(2).substring(6, 8));
		
		//insert data into database
		Connection conn=DbConnection.connectDB();
		try {
  			//prepare query runner
  			QueryRunner qRunner = new QueryRunner();
  			//prepare SQL query to insert into Table slant_delay
  			String req="";
  			req="INSERT INTO param" +
			"(name, doy," +
			"latmin," +
			"latmax, nlat, " +
			"lonmin, lonmax, " +
			"nlon, altmin," +
			"altmax, nalt, grille, " +
			"file_name, epok_deb, " +
			"epok_fin, epok_inc, date,session) " +
			"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  			
  			//insert data into database
  			inserts = qRunner.update(conn,req,
  						param_data.get(0),
  						(int)Double.parseDouble(param_data.get(1)),
  						Double.parseDouble(param_data.get(3)),
  						Double.parseDouble(param_data.get(4)),
  						(int)Double.parseDouble(param_data.get(5)),
  						Double.parseDouble(param_data.get(6)),
  						Double.parseDouble(param_data.get(7)),
  						(int)Double.parseDouble(param_data.get(8)),
  						Double.parseDouble(param_data.get(9)),
  						Double.parseDouble(param_data.get(10)),
  						(int)Double.parseDouble(param_data.get(11)),
  						param_data.get(12),
  						param_data.get(13),
  						(int)Double.parseDouble(param_data.get(14)),
  						(int)Double.parseDouble(param_data.get(15)),
  						(int)Double.parseDouble(param_data.get(16)),
  						d,session);
  			
  			//close the connection
  			DbUtils.closeQuietly(conn);
  			
		} catch (Exception e) {
			e.printStackTrace();
			}
		//test if good
			if (inserts==1)
				System.out.println("Insertion into param done !");
		
	}
	/**
	 * function read all parameters from site_all file 
	* @param 			file		String, file name, the total path
	*/
	public static void readAllGPS(String file){	
		
		//get all site data from the file and put them in gps_data
		ArrayList <String> gps_data =new ArrayList<String>();		
		int inserts =0;
		try{
		  	// Open the file that is the first 
		  	// command line parameter
		  	FileInputStream fstream = new FileInputStream(file);
		  	// Get the object of DataInputStream
		  	DataInputStream in = new DataInputStream(fstream);
		  	BufferedReader br = new BufferedReader(new InputStreamReader(in));	  
		  	String [] data;
		  	String strLine;
		 	while ((strLine = br.readLine()) != null)   			  	
		  	{
		 		data=strLine.split(" ");
		 		for(int i=0;i<data.length;i++)
		 			if (!data[i].isEmpty())
		 				gps_data.add(data[i]);
		 		
		  	}
		 		 	
		}catch (Exception e){
			//Catch exception if any
		 	 System.err.println("Error: " + e.getMessage());
		 	 }
		
		//insert data into database
		Connection conn=DbConnection.connectDB();
		try {
  			//prepare query runner
  			QueryRunner qRunner = new QueryRunner();
  			//prepare SQL query to insert into Table slant_delay
  			String req="";
  			req="INSERT INTO sites_all" +
			"(code,lat,lon, alt)"+
			"VALUES (?,?,?,?)";
  			int i=1;
  			//insert data into database
  			while (i<gps_data.size())
  			{
  			inserts = qRunner.update(conn,req,
  					gps_data.get(i),
  					Double.parseDouble(gps_data.get(i+1)),
  					Double.parseDouble(gps_data.get(i+2)),
  					Double.parseDouble(gps_data.get(i+3)));
  			i=i+4;
  			}
  			//close the connection
  			DbUtils.closeQuietly(conn);
  			
		} catch (Exception e) {
			System.err.println(e.getMessage());
			e.printStackTrace();
			}
		//test if good
			if (inserts==1)
				System.out.println("Insertion into allgps data done !");
	}
	/**
	 * function read all parameters from atmo_stan_pro file 
	* @param 			file		String, file name, the total path
	*/
	public static void readAtmoStan(String file){	
		
		ArrayList <String> atmo_stan =new ArrayList<String>();		
		int inserts =0;
		try{
			// Open the file that is the first 
		  	// command line parameter
		  	FileInputStream fstream = new FileInputStream(file);
		  	// Get the object of DataInputStream
		  	DataInputStream in = new DataInputStream(fstream);
		  	BufferedReader br = new BufferedReader(new InputStreamReader(in));	  
		   	String strLine;
		 	while ((strLine = br.readLine()) != null)   			  	
		  	{
		 				atmo_stan.add(strLine.trim());
		  	}
		}catch (Exception e){
			//Catch exception if any
		 	 System.err.println("Error: " + e.getMessage());
		 	 }
			
		//insert data into database
				Connection conn=DbConnection.connectDB();
				try {
		  			//prepare query runner
		  			QueryRunner qRunner = new QueryRunner();
		  			//prepare SQL query to insert into Table slant_delay
		  			String req="";
		  			req="INSERT INTO atmo_stan_pro" +
					"(atmo_data,session)"+
					"VALUES (?,?)";
		  			int i=0;
		  			long time = System.currentTimeMillis();
			        Timestamp session=new Timestamp(time);
		  			//insert data into database
		  			while (i<atmo_stan.size())
		  			{
		  			inserts = qRunner.update(conn,req,
		  					Double.parseDouble(atmo_stan.get(i)),
		  					session);
		  			i++;
		  			}
		  			//close the connection
		  			DbUtils.closeQuietly(conn);
		  			
				} catch (Exception e) {
					e.printStackTrace();
					}
				//test if good
					if (inserts==1)
						System.out.println("Insertion into atmo_stan done !");
		
		
		
		
	}
	/**
	 * function read all data from front.dat file 
	* @param 			file		String, file name, the total path
	*/
	public static void readFront(String file)
	{
				//get all site data from the file and put them in gps_data
				ArrayList <String> front_data =new ArrayList<String>();	
				
				//get the session timestamp
				long time = System.currentTimeMillis();
				Timestamp session=new Timestamp(time);
				
				int inserts =0;
				try{
				  	// Open the file that is the first 
				  	// command line parameter
				  	FileInputStream fstream = new FileInputStream(file);
				  	// Get the object of DataInputStream
				  	DataInputStream in = new DataInputStream(fstream);
				  	BufferedReader br = new BufferedReader(new InputStreamReader(in));	  
				  	String [] data;
				  	String strLine;
				 	while ((strLine = br.readLine()) != null)   			  	
				  	{
				 		data=strLine.split("\t");
				 		if (data.length==1)
				 			data=strLine.split(" ");
				 		
				 		for(int i=0;i<data.length;i++)
				 			if (!data[i].isEmpty())
				 				front_data.add(data[i]);
				 		
				  	}
				 		 	
				}catch (Exception e){
					//Catch exception if any
				 	 System.err.println("Error: " + e.getMessage());
				 	 }
				
				//insert data into database
				Connection conn=DbConnection.connectDB();
				try {
		  			//prepare query runner
		  			QueryRunner qRunner = new QueryRunner();
		  			//prepare SQL query to insert into Table slant_delay
		  			String req="";
		  			req="INSERT INTO front" +
					"(x,y,session)"+
					"VALUES (?,?,?)";
		  			int i=0;
		  			//insert data into database
		  			while (i<front_data.size())
		  			{
		  				if (front_data.get(i).equals(new String ("nan"))) 	front_data.set(i, "0.0");
		  				if (front_data.get(i+1).equals(new String ("nan"))) front_data.set((i+1), "0.0");
		  				
		  			inserts = qRunner.update(conn,req,
		  					Double.parseDouble(front_data.get(i).toString()),
		  					Double.parseDouble(front_data.get(i+1).toString()),
		  					session);
		  			i=i+2;
		  			}
		  			
				} catch (Exception e) {
					System.err.println(e.getMessage());
					e.printStackTrace();
					}
				//test if good
				if (inserts==1)
					System.out.println("Insertion into front done !");
				//close the connection
	  			DbUtils.closeQuietly(conn);
				
	}
	/**
	 * function to get the list of all gps codes from the database 
	* @return			ArrayList 	<String>
	*/
	@SuppressWarnings("rawtypes")
	public static ArrayList <String> getAllGPSCodes(){
		
		ArrayList <String> gps_codes =new ArrayList<String>();
		Object s=null;	
		
		Connection conn=DbConnection.connectDB();
		try {
			List  list1 = new ArrayList();	
			QueryRunner qRunner = new QueryRunner();		
			list1 =(List) qRunner.query(
				conn,
				"select code from sites_all",
				new ArrayListHandler()
				);			
					for(int i=0;i<(list1.size());i++)
					{
						s=((Object[]) list1.get(i))[0];
						gps_codes.add(s.toString());
					}		
		} catch (Exception e) {
			e.printStackTrace();
			}
		DbUtils.closeQuietly(conn);
		return gps_codes;
		
	
	}
	/**
	 * function to read gps data from sites.gps and insert into database
	 * and if the gps information does not exist in sites_all table, we add it
	* @param 			file		String, file name, the total path to sites.gps
	*/
    public static void readGPSData(String file)
	{
    	ArrayList <String> gps_codes =new ArrayList<String>();
    	gps_codes=getAllGPSCodes();
    	
    	//get all site data from the file and put them in gps_data
    			ArrayList <String> gps_data =new ArrayList<String>();		
    			int inserts =0;
    			try{
    			  	// Open the file that is the first 
    			  	// command line parameter
    			  	FileInputStream fstream = new FileInputStream(file);
    			  	// Get the object of DataInputStream
    			  	DataInputStream in = new DataInputStream(fstream);
    			  	BufferedReader br = new BufferedReader(new InputStreamReader(in));	  
    			  	//to to stock the result of the query
    			  	String [] data;
    			  	String strLine;
			        
    			 	while ((strLine = br.readLine()) != null)   			  	
    			  	{
    			 		data=strLine.split(" ");
    			 		for(int i=0;i<data.length;i++)
    			 			if (!data[i].isEmpty())
    			 				gps_data.add(data[i]);    			 		
    			  	}
    			 		 	
    			}catch (Exception e){
    				//Catch exception if any
    			 	 System.err.println("Error: " + e.getMessage());
    			 	 }
    			//get the current time for the session data
			  	long time = System.currentTimeMillis();
		        Timestamp session=new Timestamp(time);
    			//insert data into database
    			Connection conn=DbConnection.connectDB();
    			try {
    	  			//prepare query runner
    	  			QueryRunner qRunner = new QueryRunner();
    	  			//prepare SQL query to insert into Table slant_delay
    	  			String req="";
    	  			String req1="";
    	  			req="INSERT INTO sites_gps" +
    				"(code,session)"+
    				"VALUES (?,?)";
    	  			int i=1;
    	  			//insert data into database
    	  			while (i<gps_data.size())
    	  			{
    	  				if(gps_codes.contains(gps_data.get(i)))
    	  				{
    	  					inserts = qRunner.update(conn,req,
    	    	  					gps_data.get(i),
    	    	  					session);
    	  				}
    	  				//if the site code is not in the table of all sites in the database
    	  				//insert it
    	  				else
    	  				{req1="INSERT INTO sites_all" +
    	  	    				"(code,lat,lon,alt)"+
    	  	    				"VALUES (?,?,?,?)";
    	  				inserts = qRunner.update(conn,req1,
    	  	  					gps_data.get(i),
    	  	  					Double.parseDouble(gps_data.get(i+1)),
    	  	  					Double.parseDouble(gps_data.get(i+2)),
    	  	  					Double.parseDouble(gps_data.get(i+3)));
    	  					
    	  				}    	  			
    	  			i=i+4;
    	  			}
    	  			//close the connection
    	  			DbUtils.closeQuietly(conn);
    	  			
    			} catch (Exception e) {
    				e.printStackTrace();
    				}
    			//test if good
    				if (inserts==1)
    					System.out.println("Insertion into gps data done !");
    	
	}
	/**
	 * function read all slant file in the repository and call 
	 * "readSlantFile" to insert values into data base
	* @param 			repository		String, the repository of slant files
	*/
    public static void getAllSlantData(String repository)
	{
    	final int threadNumber =6;
    	
    	ExecutorService executor = Executors.newFixedThreadPool(threadNumber);
		 ArrayList <String> file_list =new ArrayList<String>();
		 File f= new File(repository);
		 file_list=listeRepertoire(f);
		 boolean [] finishFiles=new boolean [file_list.size()];
			for (int i=0;i<file_list.size();i++)
			{
				
				if(finishFiles[i]==false)
				{
					finishFiles[i]=true;
					executor.execute(new ParallelReading(file_list.get(i).toString()));
				}
				
				//System.out.println("\t"+file_list.get(i).toString());
				
				/*
				String s=file_list.get(i).toString();
				System.out.println("**************************************************");		
				System.out.println("**************************************************");			
				System.out.println("******Begin Getting slant Data from File "+i+"**********");		        
		            readSlantFile((file_list.get(i).toString()));
				System.out.println("------End Getting slant Data from File "+i+"------------");
				System.out.println("--------------------------------------------------");
				System.out.println("--------------------------------------------------");
				*
				*/
				
			}
			

	        //System.out.println("Starting shutdown...");
	        executor.shutdown();
	        while (!executor.isTerminated()) {    }	
	 
	        
	        System.out.println("All done!");
		
	}
	/**
	 * function read all rinex file in the repository and call 
	 * "readRinexFile" to insert values into data base
	* @param 			repository		String, the repository of slant files
	*/
	public static void getAllRinexData(String repository)
	{
		
		 String[] file_list;
		 File f= new File(repository);
		 file_list=f.list();		 
		 System.out.println(file_list.length);
			for (int i=0;i<file_list.length;i++)
			{
				//System.out.println("**************************************************");		
				//System.out.println("**************************************************");			
				System.out.println("******Begin Getting rinex Data from File "+i+"**********");
				readRinexFile(repository+"/"+file_list[i].toString());
				/*
				System.out.println("------End Getting rinex Data from File "+i+"------------");
				System.out.println("--------------------------------------------------");
				System.out.println("--------------------------------------------------");
				*/
				System.gc();
			}
		
	}
	/**
	 * function read all igs file in the repository and call 
	 * "readIgsFile" to insert values into data base
	* @param 			repository		String, the repository of slant files
	*/
	public static void getAllIgsData(String repository)
	{
		
		 String[] file_list;
		 File f= new File(repository);
		 file_list=f.list();		 
		 System.out.println(file_list.length);
			for (int i=0;i<file_list.length;i++)
			{
				//System.out.println("**************************************************");		
				//System.out.println("**************************************************");			
				System.out.println("******Begin Getting igs Data from File "+i+"**********");
				readIgsFile(repository+"/"+file_list[i].toString());
				/*
				System.out.println("------End Getting igs Data from File "+i+"------------");
				System.out.println("--------------------------------------------------");
				System.out.println("--------------------------------------------------");
				*/
				System.gc();
			}
		
	}
	/**
	 * function to read gps data from sites.gps and insert into database
	 * and if the gps information does not exist in sites_all table, we add it
	* @param 			file		String, file name, the total path to sites.gps
	*/
    public static void readintreliefMattix(String file)
	{
    	
    	int inserts=0;
    	  //an arraylist to contain the rinex data
		  ArrayList <String> matrixData =new ArrayList<String>();		
		  //String to get the data line each time
		  String [] data_line;
			try{
			  	// Open the file that is the first 
			  	// command line parameter
			  	FileInputStream fstream = new FileInputStream(file);
			  	// Get the object of DataInputStream
			  	DataInputStream in = new DataInputStream(fstream);
			  	BufferedReader br = new BufferedReader(new InputStreamReader(in));	  
			  	String strLine;
			  	int lineNB=1;
			  	int currentValue=0;
			  	//extract data from file and putting them in ArratyList rinex_data 
			  	while ((strLine = br.readLine()) != null)   			  	
			  	{
			  			data_line=strLine.split("\t");
			  	 		if (data_line.length==1)
			  	 			data_line=strLine.split(" ");
			  	 		
			  			for (int i=0; i<data_line.length;i++)
			  			{
			  				if (!data_line[i].isEmpty())										
			  					matrixData.add(data_line[i]);
			  			}			  			
			  			
			  	}	
			  	
			  	/*for (int i=0;i<matrixData.size();i+=101)
			  	{
			  		System.out.println("\nline= "+lineNB+"\n");
			  		currentValue+=i;
		  			//System.out.println("line= "+lineNB+" line size="+"\t"+matrixData.get(i+100));
		  			lineNB++;
		  			for (int  j=0;j<=100;j++)
		  			{
		  				if ((j%10)==0)
		  				System.out.print("\t"+matrixData.get(i+j));
		  			}
			  		
			  	}*/
			  	
			 }
			catch (Exception e){
				//Catch exception if any
			 	 System.err.println("Error: " + e.getMessage());
				 }
    	
			

			//insert data into database
			Connection conn=DbConnection.connectDB();
			try {
	  			//prepare query runner
	  			QueryRunner qRunner = new QueryRunner();
	  			//prepare SQL query to insert into Table slant_delay
	  			String req="";
	  			req="INSERT INTO intrelief_matrix" +
				"(x,y,value)"+
				"VALUES (?,?,?)";
	  			int lineNB=0;
	  			for (int i=0;i<matrixData.size();i+=101)
			  	{
			  		
		  			for (int  j=0;j<=100;j++)
		  			{
		  				inserts = qRunner.update(conn,req,
		  						lineNB,
		  						j,
			  					Double.parseDouble(matrixData.get(i+j).toString()));
		  				
		  			}
		  			lineNB++;
			  	}
	  			
	  			
			} catch (Exception e) {
				System.err.println(e.getMessage());
				e.printStackTrace();
				}
			//test if good
			if (inserts==1)
				System.out.println("Insertion into intreliefMatrix done !");
			//close the connection
  			DbUtils.closeQuietly(conn);
			
    	
	}
	
	/**
	* function to make the get the connexion paramaters from file
	* @return			void		
	*/
	public static void getFilesPath()
	{
		String file="filesPath.txt";
		try{
		  	// Open the file that is the first 
		  	// command line parameter
		  	FileInputStream fstream = new FileInputStream(file);
		  	// Get the object of DataInputStream
		  	DataInputStream in = new DataInputStream(fstream);
		  	BufferedReader br = new BufferedReader(new InputStreamReader(in));			  	
		  	String strLine;
		 	while ((strLine = br.readLine()) != null)   			  	
		  	{
		 		if (strLine.contains("SlantFolderPath"))
		 			SlantFolderPath=DbConnection.getParam(strLine);
		 		if (strLine.contains("RinexFolderPath"))
		 			RinexFolderPath=DbConnection.getParam(strLine);
		 		if (strLine.contains("IgsFolderPath"))
		 			IgsFolderPath=DbConnection.getParam(strLine);
		 		if (strLine.contains("ParamFilePath"))
		 			ParamFilePath=DbConnection.getParam(strLine);
		 		if (strLine.contains("AllGPSFilePath"))
		 			AllGPSFilePath=DbConnection.getParam(strLine);
		 		if (strLine.contains("GPSDataFilePath"))
		 			GPSDataFilePath=DbConnection.getParam(strLine);
		 		if (strLine.contains("AtmoStanFilePath"))
		 			AtmoStanFilePath=DbConnection.getParam(strLine);
		 		if (strLine.contains("FrontFilePath"))
		 			FrontFilePath=DbConnection.getParam(strLine);
		 		if (strLine.contains("intreliefMatrix"))
		 			intreliefMatrix=DbConnection.getParam(strLine);
		 		
		 		
		  	}
 		 	
		}catch (Exception e){
			//Catch exception if any
		 	 System.err.println("Error: " + e.getMessage());
		 	 }
		  	
	}
	
	public static void main(String args[])
  {
		
		DbConnection.getConnexionParam();
		//get the session timestamp
		long time = System.currentTimeMillis();
        Timestamp timeDate=new Timestamp(time);
        
        		
        getFilesPath();
        
        
        try{
        readintreliefMattix(intreliefMatrix);
        	}catch (Exception e){
    		//Catch exception if any
    	 	 System.err.println("Error: " + e.getMessage());
    	 	 }
        
        try{
        getAllRinexData		(RinexFolderPath);
        	}catch (Exception e){
        	//Catch exception if any
        	System.err.println("Error: " + e.getMessage());
        	}
        
        try{
        getAllIgsData		(IgsFolderPath);
        }catch (Exception e){
		//Catch exception if any
	 	 System.err.println("Error: " + e.getMessage());
	 	 }
        
        try{
        readParamFile		(ParamFilePath);
        }catch (Exception e){
		//Catch exception if any
	 	 System.err.println("Error: " + e.getMessage());
	 	 }
        
        try{
        readAllGPS			(AllGPSFilePath);		
        }catch (Exception e){
		//Catch exception if any
	 	 System.err.println("Error: " + e.getMessage());
	 	 }
        
        try{
        readGPSData			(GPSDataFilePath);
        }catch (Exception e){
		//Catch exception if any
	 	 System.err.println("Error: " + e.getMessage());
	 	 }
        
        try{
        readAtmoStan		(AtmoStanFilePath);
        }catch (Exception e){
		//Catch exception if any
	 	 System.err.println("Error: " + e.getMessage());
	 	 }
        
        try{
        readFront			(FrontFilePath);
        }catch (Exception e){
		//Catch exception if any
	 	 System.err.println("Error: " + e.getMessage());
	 	 }
        
        try{
            getAllSlantData		(SlantFolderPath);
        	}catch (Exception e){
    		//Catch exception if any
    	 	 System.err.println("Error: " + e.getMessage());
    	 	 }
        
        
		System.out.println("Reading Data from files, and insertion into DataBase: Completed");
		
        
		//get the session timestamp
				time = System.currentTimeMillis();
		        Timestamp timeDate1=new Timestamp(time);
		        
		        System.out.println("\n\n\nStart: "+timeDate+"\nEnd: "+timeDate1);
		        
  }
}
